/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package parcview;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import parcview.interfaces.CarIF;

/**
 *
 * @author Malte
 */
public class CarQueueDraw {
    
    
    ArrayList<Point> waitingPoints = new ArrayList<Point>();
    List<CarIF> waitingCars = new ArrayList<CarIF>();
    Point counterPosition = new Point(-1000,-1000);
    
    public CarQueueDraw(ArrayList<Point> wP) {
        this.waitingPoints = wP;
    }
    public CarQueueDraw(ArrayList<Point> wP,Point cP) {
        this.waitingPoints = wP;
        this.counterPosition  = cP;
    }
 
    public void updateQueue(List<CarIF> waitingCars) {
        int counter = 0;
        this.waitingCars = waitingCars;
        if(waitingCars.size() != 0 && counter < waitingPoints.size()) {
            for(CarIF a : waitingCars) {
                if(a != null) {
                    a.setPos(waitingPoints.get(waitingPoints.size()-waitingCars.indexOf(a)-1).x,waitingPoints.get(waitingPoints.size()-waitingCars.indexOf(a)-1).y);
                    counter++;
                    if(counter >= waitingPoints.size()) 
                        break;
                }
            }
        }
    }
    
    public void drawQueue(GC g, Canvas d) {
        for(CarIF a : waitingCars) {
            if(a != null)
                a.drawCar(g,d);
        }
        g.setBackground(d.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        g.setForeground(d.getDisplay().getSystemColor(SWT.COLOR_RED));
        if(waitingCars.size() > waitingPoints.size())
            g.drawText(((Integer)(this.waitingCars.size()-waitingPoints.size())).toString(), this.counterPosition.x, this.counterPosition.y);
    }

}
